Index: lang/en_utf8/data.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/data.php,v
retrieving revision 1.53
diff -u -b -r1.53 data.php
--- lang/en_utf8/data.php	3 Apr 2007 03:32:46 -0000	1.53
+++ lang/en_utf8/data.php	21 Aug 2007 07:19:44 -0000
@@ -163,6 +163,16 @@
 $string['nomaximum'] = 'No maximum';
 $string['norecords'] = 'No entries in database';
 $string['nosingletemplate'] = 'Single template is not yet defined';
+$string['notification'] = 'Email notifications';
+$string['notifyratermail'] = '$a->username has updated their database submission
+for \'$a->database\'
+
+It is available here:
+
+    $a->url';
+$string['notifyratermailhtml'] = '$a->username has updated their database submission 
+for <i>\'$a->database\'</i><br /><br />
+    It is <a href=\"$a->url\">available on the web site</a>.';
 $string['notinjectivemap'] = 'Not an injective map';
 $string['number'] = 'Number';
 $string['numberrssarticles'] = 'RSS articles';
Index: lang/en_utf8/help/data/notification.html
===================================================================
RCS file: lang/en_utf8/help/data/notification.html
diff -N lang/en_utf8/help/data/notification.html
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lang/en_utf8/help/data/notification.html	21 Aug 2007 07:19:44 -0000
@@ -0,0 +1,6 @@
+<h1>Email notifications</h1>
+
+<p>If enabled, users capable of rating database submissions are alerted with a
+short email whenever a record in the database is added or updated.  If separate
+groups are being used, notification emails are only sent to the raters within
+the relevant group.</p>
Index: mod/data/edit.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/edit.php,v
retrieving revision 1.32
diff -u -b -r1.32 edit.php
--- mod/data/edit.php	20 Aug 2007 22:18:49 -0000	1.32
+++ mod/data/edit.php	21 Aug 2007 07:19:45 -0000
@@ -183,6 +183,8 @@
 
             add_to_log($course->id, 'data', 'update', "view.php?d=$data->id&amp;rid=$rid", $data->id, $cm->id);
 
+            data_notify_raters($data, $USER->id, $rid, $context);
+
             redirect($CFG->wwwroot.'/mod/data/view.php?d='.$data->id.'&amp;rid='.$rid);
 
         } else { /// Add some new records
@@ -246,6 +248,8 @@
 
                 add_to_log($course->id, 'data', 'add', "view.php?d=$data->id&amp;rid=$recordid", $data->id, $cm->id);
 
+                data_notify_raters($data, $USER->id, $recordid, $context);
+
                 notify(get_string('entrysaved','data'));
 
                 if (!empty($datarecord->saveandview)) {
Index: mod/data/lib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/lib.php,v
retrieving revision 1.135
diff -u -b -r1.135 lib.php
--- mod/data/lib.php	21 Aug 2007 03:38:45 -0000	1.135
+++ mod/data/lib.php	21 Aug 2007 07:19:45 -0000
@@ -698,6 +698,111 @@
 }
 
 /************************************************************************
+ * notifies raters of an updated submission                             *
+ ************************************************************************/
+function data_notify_raters($data, $userid, $recordid, $context){
+    if ($data->notification) {
+      $data->cm = get_coursemodule_from_instance('data', $data->id, $data->course);
+
+      $courseobj = get_record('course', 'id', $data->course);
+
+      if ($raters = get_raters($userid, $context, $data, $courseobj)) {
+          $strnewent  = get_string('newentry', 'data');
+
+          $user = get_record('user', 'id', $userid);
+
+          foreach($raters as $rater) {
+              global $CFG;
+
+              $info = new object();
+              $info->username = fullname($user, true);
+              $info->database = format_string($data->name,true);
+              $info->url = $CFG->wwwroot.'/mod/data/view.php?d='.$data->id."&rid=".$recordid;
+              $info->shortname = $courseobj->shortname;
+              $info->courseid = $courseobj->id;
+              $info->dbname = $data->name;
+              $info->cmid = $data->cm->id;
+              $info->strdatabases = get_string('modulenameplural', 'data');
+
+              $postsubject = $strnewent.': '.$info->username.' -> '.$data->name;
+              $posttext = email_notify_text($info);
+              $posthtml = ($rater->mailformat == 1) ? email_notify_html($info) : '';
+
+              @email_to_user($rater, $user, $postsubject, $posttext, $posthtml);
+      }
+    }
+  }
+}
+
+/************************************************************************
+ * returns a list of users capable of rating the user's submission      *
+ ************************************************************************/
+function get_raters($userid, $context, $data, $course) {
+  $potraters = get_users_by_capability($context, 'mod/data:rate', '', '', '', '', '', '', false, false);
+
+        $raters = array();
+        if (groupmode($course, $data->cm) == SEPARATEGROUPS) {   // Separate groups are being used
+            if ($groups = groups_get_all_groups($data->course, $userid)) {  // Try to find all groups
+                foreach ($groups as $group) {
+                    foreach ($potraters as $t) {
+                        if ($t->id == $userid) {
+                            continue; // do not send self
+                        }
+                        if (groups_is_member($group->id, $t->id)) {
+                            $raters[$t->id] = $t;
+                        }
+                    }
+                }
+            } else {
+                // user not in group, try to find raters without group
+                foreach ($potraters as $t) {
+                    if ($t->id == $userid) {
+                        continue; // do not send self
+                    }
+                    if (!groups_get_all_groups($data->course, $t->id)) {
+                        $raters[$t->id] = $t;
+                    }
+                }
+            }
+        } else {
+            foreach ($potraters as $t) {
+                if ($t->id == $userid) {
+                    continue; // do not send self
+                }
+                $raters[$t->id] = $t;
+            }
+        }
+        return $raters;
+}
+
+/************************************************************************
+ * Creates the text content for email notifications to raters           *
+ ************************************************************************/
+function email_notify_text($info) {
+    $posttext  = format_string($info->shortname).' -> '.$info->strdatabases.' -> '.
+                 format_string($info->dbname)."\n";
+    $posttext .= '---------------------------------------------------------------------'."\n";
+    $posttext .= get_string("notifyratermail", "data", $info)."\n";
+    $posttext .= "\n---------------------------------------------------------------------\n";
+    return $posttext;
+}
+
+/************************************************************************
+ * Creates the HTML content for email notifications to raters           *
+ ************************************************************************/
+function email_notify_html($info) {
+    global $CFG;
+    $posthtml  = '<p><font face="sans-serif">'.
+                 '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$info->courseid.'">'.format_string($info->shortname).'</a> ->'.
+                 '<a href="'.$CFG->wwwroot.'/mod/data/index.php?id='.$info->courseid.'">'.$info->strdatabases.'</a> ->'.
+                 '<a href="'.$CFG->wwwroot.'/mod/data/view.php?id='.$info->cmid.'">'.format_string($info->dbname).'</a></font></p>';
+    $posthtml .= '<hr /><font face="sans-serif">';
+    $posthtml .= '<p>'.get_string('notifyratermailhtml', 'data', $info).'</p>';
+    $posthtml .= '</font><hr />';
+    return $posthtml;
+}
+
+/************************************************************************
  * returns a summary of data activity of this user                      *
  ************************************************************************/
 function data_user_outline($course, $user, $mod, $data) {
Index: mod/data/mod_form.php
===================================================================
RCS file: /cvsroot/moodle/moodle/mod/data/mod_form.php,v
retrieving revision 1.21
diff -u -b -r1.21 mod_form.php
--- mod/data/mod_form.php	20 Aug 2007 14:04:10 -0000	1.21
+++ mod/data/mod_form.php	21 Aug 2007 07:19:45 -0000
@@ -45,6 +45,9 @@
         $mform->addElement('select', 'comments', get_string('comments', 'data'), $ynoptions);
         $mform->setHelpButton('comments', array('comments', get_string('allowcomments', 'data'), 'data'));
 
+        $mform->addElement('select', 'notification', get_string('notification', 'data'), $ynoptions);
+        $mform->setHelpButton('notification', array('notification', get_string('notification', 'data'), 'data'));
+
         $mform->addElement('select', 'approval', get_string('requireapproval', 'data'), $ynoptions);
         $mform->setHelpButton('approval', array('requireapproval', get_string('requireapproval', 'data'), 'data'));
 
